<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属部门" prop="deptName">
        <el-select v-model="queryParams.deptName" placeholder="所属部门" clearable size="small">
          <el-option
            v-for="dict in deptNameOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="患者名称" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者姓名"
          clearable
          size="small"
          style="width:170px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="挂号类型" prop="postName">
        <el-select v-model="queryParams.registraName" placeholder="挂号时段" clearable size="small">
          <el-option
            v-for="dict in leixingOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号时段" prop="registerTime">
        <el-select v-model="queryParams.registerTime" placeholder="挂号时段" clearable size="small">
          <el-option
            v-for="dict in registerTimeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号状态" prop="registerStatus">
        <el-select v-model="queryParams.registerStatus" placeholder="挂号状态" clearable size="small">
          <el-option
            v-for="dict in registerStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="挂号时间" prop="registerDate">
        <el-date-picker
          v-model="queryParams.registerDate"
          size="small"
          style="width:200px"
          value-format="yyyy-MM-dd"
          type="date"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="registerList" @selection-change="handleSelectionChange">
      <el-table-column label="患者姓名" align="center" prop="treatPatient.patientName" />
      <el-table-column label="挂号科室" align="center" prop="systemUser.systemDept.deptName" />
      <el-table-column label="接诊医生" align="center" prop="systemUser.userName" />
      <el-table-column label="挂号费用" align="center" prop="systemTregistraFee.registraUnitprice" />
      <el-table-column label="流水编号" align="center" prop="registerId" />
      <el-table-column label="状态" align="center" prop="registerStatus" />
      <el-table-column label="就诊日期" align="center" prop="registerDate" width="180"/>
      <el-table-column label="挂号类型" align="center" prop="systemTregistraFee.registraName" />
      <el-table-column label="挂号时段" align="center" prop="registerTime" />
      <!--<el-table-column label="操作" align="center" v-if="registerStatus = '未收费'">收费 </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
    import { listRegister, getPost, delPost, addPost, updatePost, exportPost } from "@/api/treat/register";

    export default {
        name: "Post",
        data() {
            return {
                //部门数据字典
                deptNameOptions: [{
                    "dictLabel": "内科",
                    "dictValue": "内科",
                }, {
                    "dictLabel": "外科",
                    "dictValue": "外科",
                }, {
                    "dictLabel": "骨科",
                    "dictValue": "骨科",
                }, {
                    "dictLabel": "儿科",
                    "dictValue": "儿科",
                }],
                // 状态数据字典
                registerStatusOptions: [{
                    "dictLabel": "未收费",
                    "dictValue": "未收费",
                }, {
                    "dictLabel": "待就诊",
                    "dictValue": "待就诊",
                }, {
                    "dictLabel": "正在就诊",
                    "dictValue": "正在就诊",
                }, {
                    "dictLabel": "就诊完成",
                    "dictValue": "就诊完成",
                }],
                // 门诊类型
                leixingOptions: [{
                    "dictLabel": "门诊",
                    "dictValue": "门诊",
                }, {
                    "dictLabel": "门诊+病例本",
                    "dictValue": "门诊+病例本",
                }, {
                    "dictLabel": "急诊",
                    "dictValue": "急诊",
                }, {
                    "dictLabel": "急诊+病例本",
                    "dictValue": "急诊+病例本",
                }],
                // 挂号时段数据字典
                registerTimeOptions: [{
                    "dictLabel": "上午",
                    "dictValue": "上午"
                }, {
                    "dictLabel": "下午",
                    "dictValue": "下午"
                }, {
                    "dictLabel": "晚上",
                    "dictValue": "晚上"
                }],
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 患者表格数据
                registerList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    patientName: undefined,
                    registerStatus: undefined,
                    registerDate: undefined,
                    registerTime: undefined,
                    registraName: undefined,
                    deptName: undefined
                },
                // 表单参数
                form: {},
            };
        },
        created() {
            this.getList();
            this.getDicts("sys_normal_disable").then(response => {
                this.statusOptions = response.data;
            });
        },
        methods: {
            /** 查询挂号列表 */
            getList() {
                this.loading = true;
                listRegister(this.queryParams).then(response => {
                    this.registerList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    postId: undefined,
                    postCode: undefined,
                    postName: undefined,
                    postSort: 0,
                    status: "0",
                    remark: undefined
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.postId)
                this.single = selection.length!=1
                this.multiple = !selection.length
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.postId != undefined) {
                            updatePost(this.form).then(response => {
                                this.msgSuccess("修改成功");
                                this.open = false;
                                this.getList();
                            });
                        } else {
                            addPost(this.form).then(response => {
                                this.msgSuccess("新增成功");
                                this.open = false;
                                this.getList();
                            });
                        }
                    }
                });
            },
        }
    };
</script>
